#ifndef _IUMODULEIP_HPP_
#define _IUMODULEIP_HPP_

#include <list>
#include <pthread.h>
#include "iuIPAddress.hpp"
#include "iuModuleICMP.hpp"
#include "iuRoute.hpp"

class iuPacketIP;
class iuInterface;
class iuApplication;
class iuARPEntry;

/**
 * @brief Une liste de fragments en attente d'envoi
 */
class iuFragmentList
{
public:
   ~iuFragmentList();
   bool isComplete();

   uint16_t id;
   iuIPAddress source;
   std::list<iuPacketIP *> fragments;
};

/**
 * @brief Classe chargee de gerer les differents paquets IP:
 * Elle se charge essentiellement du routage et de la fragmentation
 */
class iuModuleIP
{
public:
   iuModuleIP(iuApplication &app);
   ~iuModuleIP();

   void receivePacket(iuPacketIP &packet, iuInterface &in);
   void sendPacket(iuPacketIP &packet);
   void sendARPWaitingPackets(const iuARPEntry &entry);
   void decreaseTTL();

   iuRoute      &getRouteTable();
   iuModuleICMP &getModuleICMP();

private:
   std::list<iuPacketIP *> m_ARPWaitingPackets;
   std::list<iuFragmentList *> m_fragmentLists;

   iuModuleICMP m_moduleICMP;
   iuRoute m_routeTable;
   iuApplication &m_app;

   pthread_t m_threadTTL;
   pthread_mutex_t m_fragmentListsMutex;
   pthread_mutex_t m_ARPWaitingPacketsMutex;
};

#endif
